package com.x.uikit.router;

import android.os.Bundle;
import android.os.Parcel;
import android.os.Parcelable;

import androidx.annotation.NonNull;

/**
 * 路由信息
 */
public class XRoute implements Parcelable {

    /**
     * 路径
     */
    @NonNull
    public String path;
    /**
     * 参数
     */
    public Bundle argument;

    public XRoute(@NonNull String path) {
        this.path = path;
    }

    public XRoute(@NonNull String path, Bundle argument) {
        this.path = path;
        this.argument = argument;
    }

    protected XRoute(Parcel in) {
        path = in.readString();
        argument = in.readBundle();
    }

    public static final Creator<XRoute> CREATOR = new Creator<XRoute>() {
        @Override
        public XRoute createFromParcel(Parcel in) {
            return new XRoute(in);
        }

        @Override
        public XRoute[] newArray(int size) {
            return new XRoute[size];
        }
    };

    public static XRoute obtain(@NonNull String path) {
        return obtain(path, null);
    }

    public static XRoute obtain(@NonNull String path, Bundle argument) {
        return new XRoute(path, argument);
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(path);
        dest.writeBundle(argument);
    }
}
